package com.useeinfo.oa.modules.task.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.func.lang.StringUtils;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.task.dao.TaskOrderLogDao;
import com.useeinfo.oa.modules.task.entity.TaskOrder;
import com.useeinfo.oa.modules.task.entity.TaskOrderLog;
import com.useeinfo.oa.modules.task.enums.TaskOrderLogOperationEnum;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @auther: bin.liu
 * @Date: 2019/7/4 9:14
 * @Description: 任务单操作日志
 */
@Service("taskOrderLogBiz")
public class TaskOrderLogBiz extends CrudBiz<TaskOrderLogDao, TaskOrderLog> {


    /**
     * 操作日志
     * @param taskOrder
     * @param systemUser
     * @param taskOrderLogOperationEnum
     * @param enterprise
     * @param remark
     */
    public void addLog(TaskOrder taskOrder, SystemUser systemUser, TaskOrderLogOperationEnum taskOrderLogOperationEnum, Enterprise enterprise, String remark){
        TaskOrderLog taskOrderLog = new TaskOrderLog();
        taskOrderLog.setSystemUser(systemUser);
        taskOrderLog.setUserName(systemUser.getUserName());
        taskOrderLog.setCreateDate(new Date());
        taskOrderLog.setTaskOrder(taskOrder);
        taskOrderLog.setTaskOrderLogOperationEnum(taskOrderLogOperationEnum);
        taskOrderLog.setEnterprise(enterprise);
        String time = DateTimeUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        taskOrderLog.setDetail(systemUser.getUserName() + " 在" + time + " 对任务单" + taskOrder.getSerial() + " 进行了 " + taskOrderLogOperationEnum.getName() + " 操作 ");
        if(StringUtils.isNotBlank(remark)){
            taskOrderLog.setRemark(StringConverters.null2String(remark));
        }
        addOrUpdate(taskOrderLog);
    }
}
